package com.wl.center.task.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wl.center.model.task.*;
import com.wl.center.task.service.*;
import com.wl.center.vo.task.CustomerRecord;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CustomerRecordServiceImpl implements CustomerRecordService {
    @Autowired
    private CustomerService customerService;
    @Autowired
    private TypeService typeService;
    @Autowired
    private CountryService countryService;
    @Autowired
    private LevelService levelService;
    @Autowired
    private AgentService agentService;
    @Autowired
    private ProjectService projectService;
    @Override
    public CustomerRecord getCustomerRecord(Long customerId,QueryWrapper<Customer> wrapper) {
        Customer customer1 = customerService.getById(customerId);
        CustomerRecord customerRecord = new CustomerRecord();//创建一个中间类对象customerRecord
        Integer typeId = customer1.getTypeId();
        Integer agentId = customer1.getAgentId();
        Integer countryId = customer1.getCountryId();
        Integer levelId = customer1.getLevelId();
        Integer projectId = customer1.getProjectId();
        Type type = typeService.getById(typeId);
        Country country = countryService.getById(countryId);
        Agent agent = agentService.getById(agentId);
        Level level = levelService.getById(levelId);
        Project project = projectService.getById(projectId);
        String typeName = type.getName();
        String countryName = country.getName();
        String agentName = agent.getName();
        String levelLevel = level.getLevel();
        String projectName = project.getName();
        BeanUtils.copyProperties(customer1,customerRecord);//将customer1中的其他同名属性移植给customerRecrd中间类
        customerRecord.setTypeName(typeName);
        customerRecord.setCountryName(countryName);
        customerRecord.setAgentName(agentName);
        customerRecord.setLevelName(levelLevel);
        customerRecord.setProjectName(projectName);
        return customerRecord;
    }

    //2.下拉显示可选国家
    public List<Country> getCountry(){
        QueryWrapper<Country> wrapper = new QueryWrapper<>();
        wrapper.eq("status",1);//配置信息是1才是有效
        List<Country> countryList = countryService.list(wrapper);
        return countryList;
    }

    @Override
    public List<Agent> getAgent() {
        QueryWrapper<Agent> wrapper = new QueryWrapper<>();
        wrapper.eq("status",1);//配置信息是1才是有效
        List<Agent> agentList = agentService.list(wrapper);
        return agentList;
    }

    @Override
    public List<Project> getProject() {
        QueryWrapper<Project> wrapper = new QueryWrapper<>();
        wrapper.eq("status",1);//配置信息是1才是有效
        List<Project> projectList = projectService.list(wrapper);
        return projectList;
    }

    @Override
    public List<Type> getType() {
        QueryWrapper<Type> wrapper = new QueryWrapper<>();
        wrapper.eq("status",1);//配置信息是1才是有效
        List<Type> typeList = typeService.list(wrapper);
        return typeList;
    }

}
